<template>
	<view class="beiou">
		<view class="head">
			<view class="back" @click="goBack">
				<uni-icons type="back" size="28" color="#232e3d"></uni-icons>
			</view>
			<scroll-view scroll-x="true" class="head-scroll" enable-flex="true" :style="{width: wh + 'px'}">
				<view v-for="(item,i) in datas" :key="i" :class="['head-item',i === isactive ? 'active': '']"
					@click="getCode(i)">
					{{item.title}}
				</view>
			</scroll-view>
		</view>
		<view class="content">
			<view class="item" v-for="(item,i) in main" :key="i">
				<view class="item-banner">
					<image :src="item.img1"></image>
				</view>
				<view class="item-name">
					{{item.name}}
				</view>
				<view class="item-intro">
					{{item.intro}}
				</view>
				<view class="item-details">
					<view class="details-img">
						<image :src="item.img2"></image>
					</view>
					<view class="details-img">
						<image :src="item.img3"></image>
					</view>
					<view class="details-img">
						<image :src="item.img4"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				datas: [],
				main: [],
				wh: 0,
				isactive: 0
			}
		},
		methods: {
			async getBeiouData() {
				const res = await uni.$http.get("/menu");
				const data = res.data.data[1].children;
				this.datas = data;
				this.main = data[0].children;
			},
			goBack() {
				uni.navigateBack({});
			},
			getCode(i) {
				this.isactive = i;
				this.main = this.datas[this.isactive].children;
				if(this.main == undefined){
					uni.showToast({
						title:"暂无数据",
						icon:"none"
					})
				}
			}
		},
		onLoad() {
			this.getBeiouData();
			const sysInfo = uni.getSystemInfoSync();
			this.wh = sysInfo.windowWidth - 60;
		}
	}
</script>

<style lang="scss">
	.beiou {

		// 头部导航栏
		.head {
			width: 100%;
			height: 60rpx;
			margin-top: 140rpx;
			display: flex;
			align-items: center;

			.back {
				height: 60rpx;
				margin-bottom: 20rpx;
			}

			.head-scroll {
				height: 60rpx;
				margin-left: 10rpx;
				display: flex;

				.head-item {
					text-align: center;
					white-space: nowrap;
					padding: 0 10rpx;
					margin-right: 110rpx;
				}

				.active {
					border-bottom: 1px solid #232e3d;
				}
			}
		}

		// 主体内容
		.content {
			width: 100%;

			.item {
				padding: 20rpx;
				margin: 30rpx 0;

				.item-banner {

					image {
						width: 100%;
					}
				}

				.item-name {
					font-size: 30rpx;
					color: #232e3d;
					margin: 10rpx 0 24rpx;
				}
				.item-intro {
					font-size: 22rpx;
					color: #8a94a1;
				}

				.item-details {
					margin-top: 60rpx;
					display: flex;
					justify-content: space-between;
					
					.details-img{
						width: 200rpx;
						height: 100rpx;
						
						image{
							width: 100%;
							height: 100%;
						}
					}
					
				}
			}
		}
	}
</style>
